﻿using DataAccess.DAL;
using DataAccess.DTO;
using DataAccess.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace Api.Controllers
{
    /// <summary>
    /// 阿里妈妈 接口
    /// </summary>
    public class AlimamaController : BaseController
    {
        /// <summary>
        /// 添加妈妈账号
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public HttpResponseMessage Post(Alimama model)
        {
            Result result = new Result() {  State=false,Message="失败"};
            if (model == null)
            {
                result.Message="请求参数不正确";
                return  ResultHand.OnResult(result);
            }
            if (model.promoter_id > 0 || !string.IsNullOrEmpty(model.alimamaid))
            {
                AlimamaDAL dal = new AlimamaDAL();
                if (!dal.Exist_alimamaid(model.alimamaid))
                {
                    if (dal.Insert(model))
                    {
                        result.State = true;
                        result.Message = "添加成功";
                        return ResultHand.OnResult(result);
                    }

                }
                else
                {
                    result.Message = "该联盟账号已经存在";
                    return ResultHand.OnResult(result);
                }

            
            }


             return ResultHand.OnResult(result);
        }

    }
}
